package zhoug.player.exo;


import androidx.media3.common.MediaItem;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.exoplayer.hls.DefaultHlsDataSourceFactory;
import androidx.media3.exoplayer.hls.HlsMediaSource;
import androidx.media3.exoplayer.rtsp.RtspMediaSource;

/**
 * 用于创建 MediaSource
 *
 * @Author: zhoug
 * @Date: 2023/1/9
 * @Description:
 */
 @UnstableApi class MediaSourceFactory {

    /**
     * 创建Hls
     *
     * @param mediaItem
     * @return
     */
    public static HlsMediaSource createHlsMediaSource(MediaItem mediaItem) {
        DefaultHlsDataSourceFactory factory = new DefaultHlsDataSourceFactory(ExoPlayerFactory.getDefaultHttpDataSourceFactory());
        HlsMediaSource mediaSource = new HlsMediaSource.Factory(factory)
                .setAllowChunklessPreparation(false)
                .createMediaSource(mediaItem);
        return mediaSource;
    }

    /**
     * 创建RTSP
     * @param mediaItem
     * @return
     */
    public static RtspMediaSource createRtspMediaSource(MediaItem mediaItem) {
        RtspMediaSource mediaSource = new RtspMediaSource.Factory()
                .createMediaSource(mediaItem);
        return mediaSource;
    }



}
